// CSE 142 Winter 2008, Marty Stepp // // This program checks whether two words rhyme (end with the same 2 letters) // or alliterate (start with the same letter) using String objects. import java.util.*; public class Rhyme { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Type two words: "); String word1 = console.next(); String word2 = console.next(); // example: if word1 has 10 letters, // they are numbered 0-9 // the last 2 are #8 and #9 String last2 = word2.substring(word2.length() - 2, word2.length()); if (word1.endsWith(last2)) { System.out.println("They rhyme!"); } String first = word2.substring(0, 1); if (word1.startsWith(first)) { System.out.println("They alliterate!"); } } }